from analysisJson import get_only_values
import xlrd
# -*- coding:utf-8  -*-
# @Time    : 2021/5/16 23:05
__author__ = 'wangd'
linelist=[]

def checkApp(ipaddress,appLog):
    eventids = get_only_values("eventid",appLog,[])
    if eventids == []:
        print("the json no eventid")
    else:
        eventidOfLog=eventids[0]
        check_log_excel("app",eventidOfLog,appLog)


def check_log_excel(sheetname,eventidOfLog,appLog):
    allresult=""
    excle_name = xlrd.open_workbook("checkmd.xlsx")
    sheet_name = excle_name.sheet_by_name('app')
    numOfrows=sheet_name.nrows  #行数.
    numOfcolumns=sheet_name.ncols #列数
    for row in range(1,numOfrows):
        #eventidOfExcel = sheet_name.cell_value(row, 1)#获取每行对应event值
        if row in linelist:
            continue
        otherParameterOfExcel = sheet_name.row_values(row, 0, numOfcolumns)#获取行所有参数
        while '' in otherParameterOfExcel:
            otherParameterOfExcel.remove("")
        eventidOfExcel = otherParameterOfExcel[1]
        if eventidOfLog == eventidOfExcel:
            allresult =str(row)+otherParameterOfExcel[0]+ " eventid:" + str(eventidOfLog)+" "
            if len(otherParameterOfExcel) > 2:
                for other_cx_from_numOfrows in (otherParameterOfExcel[2:]):
                    if "=" in other_cx_from_numOfrows:
                        cell_value=other_cx_from_numOfrows.split("=")
                        value_from_json_list = get_only_values(cell_value[0],appLog,[])
                        cell_value_cx=cell_value[1]#获取表里等号后面的值
                        value_from_json=value_from_json_list[0]
                        if type(value_from_json) is int:
                            value_from_json = str(value_from_json)
                        if cell_value_cx == value_from_json:
                            # resultevent = otherParameterOfExcel[0]+ "eventid:" + str(eventidOfLog) + "，"
                            resultother = cell_value[0] + "：" + value_from_json+" "
                            allresult = allresult + resultother
                        else:
                            break
                    else:
                        other_cx_json=get_only_values(other_cx_from_numOfrows,appLog,[])
                        if len(other_cx_json) > 0:
                            # resultevent = otherParameterOfExcel[0]+ "eventid:" + str(eventidOfLog) + "，"
                            resultother = other_cx_from_numOfrows +"："+ other_cx_json[0]
                            allresult = allresult + resultother+" "
                        else:
                            break
            else:
                pass
        else:
            continue
    result_line=allresult[0:1]
    linelist.append(int(result_line))
    print(allresult[0:1])

def print_result(ip,resultstring):
    pass